package com.gzx.spring.apis.tests.huarong;

import cn.hutool.core.codec.Base64;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.crypto.SecureUtil;
import com.gzx.risk.core.vo.credit.C9004;
import com.gzx.spring.apis.utils.HuarongUtil;
import com.gzx.risk.core.utils.ImageUtil;
import com.gzx.spring.apis.utils.RequestUtil;
import lombok.extern.slf4j.Slf4j;

import java.io.File;
import java.util.Date;

@Slf4j
public class C9004Demo {
    private static String privateKeyBase64 = "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBALlx4dNHzk4Jub" +
            "Ayg8hikI9T8pXJ75HQ4uR58qub/a7PuXXrKRB2MbbAuhpC3oJotLTGMm3TvyKFIL9tnItMqOpG3cK4jR977i5DFi+DJUFBH" +
            "IIvIZqsLmioUxej8bHobtdcTGf2GWR9kChiCSvltUczOM7Yzkz6gkwcbA3i7ksPAgMBAAECgYAE4Y99HS279huSHLJFSvrd" +
            "GuuOr8MDhokCVIdjpvZ1bHhIN0lcapACbG45lLsAmbrv6yuWonUsdm6XO05ciEcF4A1kd4if830RG1emeAMsulHTK3PrRqD" +
            "+H175DzbJsdACCUFqyt0P5DYN5ZleUXF1/x0faoBXyVURdy8R6hYoiQJBAPTG8LP9uL1DzqeANrqK7OEf7pe5clpauyx5a+" +
            "yP9WupO4WrWyzfHz+ixs2Oh4q1wEHgN145j5/4Y6rie+VErzMCQQDB8ohFZl6QzjMGeVuGBYRik26+3qAmc9grsm2BrnnDm" +
            "wnqmLtrAvOUArxOsGCP3QgecZf61uLM1S4CJ0+hV+S1AkA0xWMFWvDmFOVLpU+nPeY9zrWQjlGB+0eZGgBTeuHNOSn08nFw" +
            "phXFkWFM1aqRFAgD68PkE4LMWS+bmsJdNkaTAkEAhdZA9Ws8LL8udPRAFU8vWPsWfD6S05YzgYwCh3AIdNRDVpGJG8KQpf3" +
            "xRnfuWriTxrZqw12QavtdYX0RNWy61QJAYzVizCubHZDIDH/akxUn6RyDtGFuepIUn62jyDLQPilR/LUtD7Rv10XrsPSf4B" +
            "sCQKvz1ZCvEMDIMUZxC/Y06A==";// rsa私钥
    private static String publicKeyBase64 = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC5ceHTR85OCbmwMoPIYpCPU/K" +
            "Vye+R0OLkefKrm/2uz7l16ykQdjG2wLoaQt6CaLS0xjJt078ihSC/bZyLTKjqRt3CuI0fe+4uQxYvgyVBQRyCLyGarC5oqF" +
            "MXo/Gx6G7XXExn9hlkfZAoYgkr5bVHMzjO2M5M+oJMHGwN4u5LDwIDAQAB";// rsa公钥
    private static String desKey = "12345678";// des盐key
    private static String md5Key = "6y5kbbwfzfd6iygvoei5";// mk5key
    private static String post_url_base = "https://test.xinghuarong.com/api/v1.1";// 征信查询请求地址
    private static String merchantId = "100000205";// 机构编号

    public static void main(String[] args) throws Exception {
        C9004();
    }

    public static void C9004() throws Exception {
        HuarongUtil huarongUtil = new HuarongUtil().publicKeyBase64(publicKeyBase64).privateKeyBase64(privateKeyBase64)
                .merchantId(merchantId).post_url_base(post_url_base).desKey(desKey).md5Key(md5Key);
        C9004 c9004 = new C9004();
        c9004.setRequestNo(RequestUtil.getRequestNo());
        c9004.setQueryName(SecureUtil.des(desKey.getBytes()).encryptBase64("秦鹏"));
        c9004.setQueryIdNo(SecureUtil.des(desKey.getBytes()).encryptBase64("510622198501060923"));
        c9004.setQueryPhone(SecureUtil.des(desKey.getBytes()).encryptBase64("13539291804"));
        c9004.setQueyCardNo(SecureUtil.des(desKey.getBytes()).encryptBase64("6228481398716951576"));
        c9004.setVeriFaceTime(DateUtil.now());
        c9004.setAuthTime(DateUtil.now());

        File mergeFile = ImageUtil.mergeTwoFromInternet(
                FileUtil.newFile("risk-apis/src/test/java/com/gzx/spring/apis/tests/huarong/国正信测试图片.jpg"),
                FileUtil.newFile("risk-apis/src/test/java/com/gzx/spring/apis/tests/huarong/国正信测试图片.jpg"),
                "idCardFile");
        File idCardFile = ImageUtil.scaleImages(mergeFile, "反面正面");// 设置图片分辨率
        c9004.setIdCardFile(Base64.encode(idCardFile));

        c9004.setOtherAuthFile(Base64.encode(
                FileUtil.newFile("risk-apis/src/test/java/com/gzx/spring/apis/tests/huarong/国正信测试图片.jpg")));
        c9004.setCaFile(Base64.encode(
                FileUtil.newFile("risk-apis/src/test/java/com/gzx/spring/apis/tests/huarong/华融资信--征信查询授权书.pdf")));
        c9004.setOtherFile(Base64.encode(
                FileUtil.newFile("risk-apis/src/test/java/com/gzx/spring/apis/tests/huarong/华融资信--委托担保申请书.pdf")));
        File identFile = ImageUtil.scaleImages(
                FileUtil.newFile("risk-apis/src/test/java/com/gzx/spring/apis/tests/huarong/国正信测试图片.jpg"),
                "identFile");// 设置图片分辨率
        c9004.setIdentFile(Base64.encode(identFile));
        c9004.setQueryDate(DateUtil.format(new Date(), "yyyyMMdd"));
        c9004.setAuthIndexId("T20190301AND111111000000");
        log.info(huarongUtil.C9004(c9004));
    }

}
